package zju.ccnt.rest.service.util;

import org.springframework.data.domain.Sort;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zha on 14/11/11.
 */
public class ServiceUtil {
    public static Sort getSorter(String [] sort) {
        Sort rsort = null;
        if(sort != null && sort.length > 0) {
            List<Sort.Order> orders = new LinkedList<Sort.Order>();
            for(String s : sort) {
                System.out.println(s);
                String [] temp = s.split(":");
                if(temp.length == 1) {
                    orders.add(new Sort.Order(Sort.Direction.ASC,temp[0]));
                } else {
                    orders.add(new Sort.Order(Sort.Direction.fromStringOrNull(temp[1]),temp[0]));
                }
            }
            rsort = new Sort(orders);
        }
        return rsort;
    }

    public static String getCleanEmail(String email){
        String regex = "[@.]";
        return email.replaceAll(regex, "");
    }


}
